package com.shuyun.springmvc.showcase.sse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Random;

/**
 * Created by feng.ding on 2017/1/4.
 * SSE(Server Send Event) 服务端发送事件
 */

@Controller
public class SseController {

    @RequestMapping(value = "/push", produces = "text/event-stream")
    @ResponseBody
    public String push(){
        Random r = new Random();
        try{
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "data:Testing 1, 2, 3 " + r.nextInt() + "\n\n";
    }
}
